<?php
/**
 *Create by PhpStorm
 *User:Kendy
 *Date:2019/10/9/009
 *Time:16:47
 */
namespace app\admin\controller;
use think\Db;
use app\admin\model\LogStaffLogins as lsl;
use app\admin\model\LogOperates as lo;
class Logoperates extends Common{
    public function loginlist(){
        if (request()->isAjax()) {
            $data = input('param.');
            $page['limit'] = $data['limit'];
            $page['page']  = (int)$data['page'];
            $this->getPageAndSize($page);
            $where = [];
            if (isset($data['login_ip']) && $data['login_ip'] != '') {
                $where['login_ip'] = array('like', '%' . $data['login_ip'] . '%');
            } 
             if (isset($data['login_time']) && $data['login_time'] != ''){
                $created_at=explode(' - ', $data['login_time']); 
                if (isset($created_at) && is_array($created_at)){
                    foreach($created_at as $k=>$v)
                    {
                       $created_at[$k] = strtotime($v);
                    }  
                } 
                 $where['login_time']=['between',$created_at];
            }
            $logLogins = new lsl();
            $rdata = $logLogins->getLogLoginList($where, $this->from,$this->size);
            $count = $logLogins->getLogLoginCount($where);
            ajax_return(config('code.success_show'), '请求成功', $rdata, $count);
        } else {
            return view();
        }
    }
    public function operatelist(){
        if (request()->isAjax()) {
            $data = input('param.');
            $page['limit'] = $data['limit'];
            $page['page']  = (int)$data['page'];
            $this->getPageAndSize($page);
            $where = []; 
             if (isset($data['time']) && $data['time'] != ''){
                $created_at=explode(' - ', $data['time']); 
                if (isset($created_at) && is_array($created_at)){
                    foreach($created_at as $k=>$v)
                    {
                       $created_at[$k] = strtotime($v);
                    }  
                } 
                 $where['operate_time']=['between',$created_at];
            }
             if (isset($data['ip']) && $data['ip'] != '') {
                $where['operate_ip'] = array('like', '%' . $data['ip'] . '%');
            }
            if (isset($data['desc']) && $data['desc'] != '') {
                $where['operate_desc'] = array('like', '%' . $data['desc'] . '%');
            }
            $logLogins = new lo();
            $rdata = $logLogins->getLogOperateList($where, $this->from,$this->size);
            $count = $logLogins->getLogOperateCount($where);
            ajax_return(config('code.success_show'), '请求成功', $rdata, $count);
        } else {
            return view();
        }
    }
}
